// ParameterRow.qml
import QtQuick
import QtQuick.Controls

Row {
    id: root
    property string iconCode
    property string label
    property string unit
    property var model

    spacing: 20

    // 图标 + 名称
    Row {
        spacing: 10
        Rectangle {
            width: 30
            height: 30
            radius: 6
            gradient: Gradient {
                GradientStop { position: 0.0; color: "#3FCCE7" }
                GradientStop { position: 1.0; color: "#39A1F0" }
            }
            Text {
                text: iconCode
                font.family: iconFont.name
                font.pixelSize: 18
                color: "white"
                anchors.centerIn: parent
            }
        }
        Text {
            text: label
            font.pixelSize: 18
            color: "#333333"
            verticalAlignment: Text.AlignVCenter
        }
    }

    // 四组：高高限、高限、低低限、低限
    Repeater {
        model: [
            { name: "高高限", value: model.highHighLimit, enabled: model.enabledHighHigh },
            { name: "高限", value: model.highLimit, enabled: model.enabledHigh },
            { name: "低低限", value: model.lowLowLimit, enabled: model.enabledLowLow },
            { name: "低限", value: model.lowLimit, enabled: model.enabledLow }
        ]
        delegate: Row {
            spacing: 5

            CheckBox {
                checked: modelData.enabled
                onCheckedChanged: {     
                    console.log(label, modelData.name, checked)
                }
            }

            TextField {
                width: 100
                height: 30
                text: modelData.value ? modelData.value.toFixed(2) : "0.00"
                font.pixelSize: 16
                background: Rectangle {
                    radius: 6
                    color: "#f0f0f0"
                    border.color: "#cccccc"
                    border.width: 1
                }
                horizontalAlignment: TextInput.AlignHCenter
                validator: DoubleValidator { bottom: -9999.99; top: 9999.99 }
            }

            Text {
                text: modelData.name === "高高限" || modelData.name === "高限" ? unit : unit
                font.pixelSize: 16
                color: "#666666"
                verticalAlignment: Text.AlignVCenter
            }
        }
    }
}
